<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>获取到最新的hash值</title>
  <style>
    * {
      padding: 0;
      margin: 0;
      box-sizing: border-box;
    }
  </style>
</head>

<body>
  <div>
    <a href="#/zhuye">主页</a>
    <a href="#/keji">科技</a>
    <a href="#/caijing">财经</a>
    <a href="#/yule">娱乐</a>
  </div>
</body>
<script>
  "use strict";
  // 监听window的onhashchange事件，获取最新的hash值。
  window.addEventListener("hashchange", () => {
    // 通过location.hash获取最新的hash值
    console.log(location.hash);
  });
</script>

</html>